<?php
include_once "../header1.php";
?>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","upp_sch_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{
document.DelExa.SchName.value=val;
document.getElementById("List").innerHTML="";
var xmlhttp;    
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("ExaNam").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","exaname.php?q="+val,true);
xmlhttp.send();
}
</script>
<script type="text/javascript">
function getExaSubject(exa)
{
var xmlhttp;  
var sch=document.forms["DelExa"]["SchName"].value;  
var hin=exa+","+sch; 
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("Subject").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_Exa_Subject.php?q="+hin,true);
xmlhttp.send();
}
</script>
<script type="text/javascript">
function getExaDate(subj)
{
var xmlhttp;  
var sch=document.forms["DelExa"]["SchName"].value;
var exa=document.forms["DelExa"]["Exam_Name"].value;
var hin=subj+","+exa+","+sch;

if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("Exa_year").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_Exa_date.php?q="+hin,true);
xmlhttp.send();
}
</script>
<script type="text/javascript">
function DeleteVerification()
{
<?php
include_once ("../Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("../index.php");
}
   
   else
   {
   ?>
var School_Id=document.forms["DelExa"]["SchName"].value;
var Exam_Name=document.forms["DelExa"]["Exam_Name"].value;
var Year=document.forms["DelExa"]["Year"].value;
if (School_Id==""||Exam_Name=="Select One"||Year=="Select One")
  {
  alert("Please select the Exam name,School's name and Year to delete!");
  return false;
  }
  
if (School_Id!=""&&Exam_Name!="Select One"&&Year!="Select One")
{
var r=confirm("Are you sure to delete this?");
if (r==true)
  {
  return true;
 
 }

if(r==false)
  {
  return false;
  }
}
}
</script>
</head>
<body>
<?php
include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
	   <div id="lefttablereg">
<form  name="DelExa" action="#" method="POST" onSubmit="return DeleteVerification()">
<?php
if(isset($_POST['Delete']))
{
require_once 'DEL.php';
}
?>
  <table width="565" border="0" class="tablefontv">
    <tr>
      <td height="29" colspan="4"  scope="row" class="err">
      <?php
      if(isset($_POST['Delete']))
{
	if(isset($_SESSION['errorin']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo ($_SESSION['errorin']);
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['error']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo ($_SESSION['error']);
		unset($_SESSION['error']);
	}
	if(isset($_SESSION['errornorow']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
	if(isset($_SESSION['errornot']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornot'];
		unset($_SESSION['errornot']);
	}
	if(isset($_SESSION['errornot2']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornot2'];
		unset($_SESSION['errornot2']);
	}
}   
?>
</td>
      </tr>
    <tr>
      <th width="58" height="29"  scope="row" bgcolor="#6AB5FF"></th>
      <th width="117"  scope="row" bgcolor="#6AB5FF">School's Name:</th>
      <td width="186" bgcolor="#999999">
                <?php
	 	if($_SESSION['Access_Type']=="Teacher in Charge")
{
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id']; 
    $snam=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
}
	 echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' size='40' readonly='readonly'/>";
}
	else if($_SESSION['Access_Type']=="Administrator")
{
	if(!isset($SchName))
	{
		$snam=mysql_query("SELECT * FROM school WHERE School_Id='$School_Id1'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
	}
	    echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' size='40'/>";
}
	  ?></td>
      <td width="186" bgcolor="#6AB5FF">&nbsp;</td>
    </tr>
    <tr>
      <th height="30" scope="row" bgcolor="#6AB5FF"></th>
      <th height="30" scope="row" bgcolor="#6AB5FF">Exam Name:</th>
      <td bgcolor="#999999">
	  <div id="ExaNam">
	  <select name="Exam_Name" onChange="getExaSubject(this.value)">
        <?php
	if(isset($_POST['Delete']))
	  {
	 echo '<option value="'.$Exam_Name.'">'.$Exam_Name.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	 if($School_Id!="")
		{
			$exa=mysql_query("SELECT DISTINCT(Exam_Name) FROM exam WHERE School_Id='$School_Id'");
		}
		if($School_Id=="")
		{
		 
	  $exa=mysql_query("SELECT DISTINCT(Exam_Name) FROM exam");
		}
  while($row=mysql_fetch_array($exa))
  {
	 $Exa_Name=$row['Exam_Name'];

	  echo '<option value="'.$Exa_Name.'">'.$Exa_Name.'</option>';
  }
  
	  ?>
      </select></div></td>
      <td bgcolor="#6AB5FF">&nbsp;</td>
    </tr>
    <tr>
      <th height="23" scope="row" bgcolor="#6AB5FF"></th>
      <th height="23" scope="row" bgcolor="#6AB5FF">Subject:</th>
      <td bgcolor="#999999">  <div id="Subject"><select name="Subject" onchange="getExaDate(this.value)">
        <?php
	if(isset($_POST['Delete']))
	  {
	 echo '<option value="'.$Subject.'">'.$Subject.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	 if($School_Id!="")
		{
			$exa=mysql_query("SELECT DISTINCT(Subject) FROM exam WHERE School_Id='$School_Id'");
		}
		if($School_Id=="")
		{		 
	  $exa=mysql_query("SELECT DISTINCT(Subject) FROM exam");
		}
  while($row=mysql_fetch_array($exa))
  {
	 $Subj=$row['Subject'];

	  echo '<option value="'.$Subj.'">'.$Subj.'</option>';
  }
  
	  ?>
      </select></div></td>
      <td bgcolor="#6AB5FF">&nbsp;</td>
    </tr>
    <tr>
      <th height="23" scope="row" bgcolor="#6AB5FF"></th>
      <th height="23" scope="row" bgcolor="#6AB5FF">Year:</th>
      <td bgcolor="#999999"><div id="Exa_year"><select name="Year">
        <?php
	 if(isset($_POST['Delete']))
	  {
	 echo '<option value="'.$Year.'">'.$Year.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
		if($School_Id!="")
		{
			$exa=mysql_query("SELECT DISTINCT(Year) FROM exam WHERE School_Id='$School_Id'");
		}
		if($School_Id=="")
		{
	 $exa=mysql_query("SELECT DISTINCT(Year) FROM exam");
		}
  while($row=mysql_fetch_array($exa))
  {
  $Yea=$row['Year'];

	  echo '<option value="'.$Yea.'">'.$Yea.'</option>';
  }
 
	 ?>
      </select></div></td>
      <td bgcolor="#6AB5FF">&nbsp;</td>
    </tr>
    <tr>
      <td height="23" colspan="4" scope="row" bgcolor="#6AB5FF"></td>
      </tr>
  </table>

  <br/>
      <a href="DelExam.php" class="reset">Reset</a>|
    <input name="Delete" align="middle" type="submit" value="Delete" class="buttonok"/>
 <br/>
   </form>
  <?php
   	   if(isset($_POST['Delete']))
{
$SchName=$_POST['SchName'];
$name=explode(",",$SchName);
$nam=$name[0];
$tn=count($name);
for($i=1;$i<$tn;$i++)
{
if(empty($adr))
{
$adr=$name[$i];
}
else
{
$adr=$adr.",".$name[$i];
}
}
$results= mysql_query("SELECT * FROM school Where Name='$nam' AND Address='$adr'");
if($row = mysql_fetch_array($results))
{
 $School_Id=$row['School_Id'];
}
	     $Exam_Name=$_POST['Exam_Name'];
	   $Year=$_POST['Year'];
	  if($_SESSION['Access_Type']=="Teacher in Charge")
	{
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   
      if($SchName!=""&&$Exam_Name!=""&&$Year!=""&&$No_Of_Sat!="")
   {
   if($Own_School_Id=$School_Id)
   {
     echo '<table width="458" border="0" class="tablefontv">';
	  
    ?>
    <?php
       echo '<tr>';
        echo '<th width="200" height="44" scope="row">';
		echo "School Id:";
		echo '</th>';
        echo '<td width="144">';
		echo $s_name;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Exam Name:";
		echo '</th>';
        echo '<td>';
		echo $Exam;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Year:";
		echo '</th>';
        echo '<td>';
		echo $Ye;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number Of Sat_Students :";
		echo '</th>';
       echo '<td>';
	   echo $No_Of_Sat;
	   echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number Of Passed_Students:"; 
		echo '</th>';
        echo '<td>';
		echo $No_Of_Passed;
            
        echo '</td>';
      echo '</tr>';
       
   }
    echo '</table>';
	   }
   }
   }
else if($_SESSION['Access_Type']=="Administrator")
   {
       if($SchName!=""&&$Exam_Name!=""&&$Year!=""&&$No_Of_Sat!="")
   {
   echo '<table width="458" border="0" class="tablefontv">';
	  
    ?>
    <?php
       echo '<tr>';
        echo '<th width="200" height="44" scope="row">';
		echo "School Id:";
		echo '</th>';
        echo '<td width="144">';
		echo $s_name;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Exam Name:";
		echo '</th>';
        echo '<td>';
		echo $Exam;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Year:";
		echo '</th>';
        echo '<td>';
		echo $Ye;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number Of Sat_Students :";
		echo '</th>';
       echo '<td>';
	   echo $No_Of_Sat;
	   echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number Of Passed_Students:"; 
		echo '</th>';
        echo '<td>';
		echo $No_Of_Passed;
            
        echo '</td>';
      echo '</tr>';
         echo '</table>';
		 }
	}	
	}
    ?>
	 </div>
 <div id="righttablereg">
  <div class="suggestionListsch" id="List"></div>
 </div>
</div>
</div>
</div>
<div id="sidebar"><br/>
<div id="partners" class="boxed">
			<h2 class="title">EXAMS</h2>
            </div>
<?php
include_once "menu.php";
?>
<?php
include_once "../footer.php";
?>
<?php
	  }
  
?>
</body>
</html>